package com.bw.user.mvvm.viewmodel;

import androidx.databinding.ObservableField;

import com.bw.greendao.dao.UserEntityDao;
import com.bw.greendao.entity.UserDaoEntity;
import com.bw.greendao.entity.UserEntity;
import com.bw.mvvm_common.entity.BaseEntity;
import com.bw.mvvm_common.filed.UIField;
import com.bw.mvvm_common.mvvm.viewmodel.BaseViewModel;
import com.bw.user.mvvm.model.FindPwdModel;
import com.bw.user.mvvm.view.activity.AlterActivity;

import org.greenrobot.eventbus.EventBus;

import java.util.HashMap;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * @author KK
 * @description:
 * @date :2021/10/20 17:49
 */
public class FindPwdViewModel extends BaseViewModel<FindPwdModel> {

   public ObservableField<String> username = new ObservableField<>();
    public ObservableField<String> verifyCode = new ObservableField<>();
    @Override
    public void oncreate() {
        super.oncreate();

    }

    @Override
    protected void result(BaseEntity baseEntity) {
            if(baseEntity.getMessage().equals("验证成功")){
                showMsg("成功啦");
                EventBus.getDefault().postSticky(username.get());
                HashMap<String, Object> hashMap = new HashMap<>();
                hashMap.put(UIField.PAGECLAZZ, AlterActivity.class);
                startPage(hashMap);
                finishPage();
            }else {
                showMsg("失败啦");
            }
    }

    public void next(){
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("mobile",username.get());
        hashMap.put("verifyCode",verifyCode.get());
        m.requestFindpwd(hashMap)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(this);
    }

    public void back(){
        finishPage();
    }
}
